#pragma once
#include "mapwidget.h"
#include "RadarRing.h"
#include <map>
#include "../Target/data_interface.h"
#include <set>

class target_draw_base;

class MainMap : public MapWidget
{
    typedef std::map<unsigned int, boost::shared_ptr<target_draw_base> >::iterator TargetDrawIterator;

    Q_OBJECT
public:
    MainMap(QWidget *parent = NULL, int map_key = 0);
    ~MainMap(void);

    void SetGpsLocation(double longitude, double latitude, double altitude = 0);

    void DrawAllTarget(QPainter& painter);
    void SetDrawColor(TARGET_TYPE type, QColor color, QColor track_color);

public Q_SLOTS:
    void SetCenter(double, double);
    void SetSelectedTarget(info_keys key);
    void SetTargetColor(QColor color, unsigned int target_type, unsigned int color_set_type);
    void SetRadarRingStatus(unsigned char);
    void CheckTargetTimeout();
    void SetGpsLocationSlot(double longitude, double latitude, double altitude);

Q_SIGNALS:
    void map_draw_finished();
    void select_target(const info_keys &key);
    void leftclicked_target(const info_keys &key, QPoint pos);
    void gps_location_changed(double, double, double);

protected:
    unsigned int RandomX(unsigned int x = 256);

    virtual void resizeEvent ( QResizeEvent * event);
    virtual void mouseMoveEvent(QMouseEvent * event);
    virtual void mouseReleaseEvent(QMouseEvent *event);
    virtual void keyPressEvent(QKeyEvent *);
    virtual void DrawCustom(QPainter &painter);
    virtual void DrawCustomCache(QPainter &painter);

private:
    void DrawRadarRing(QPainter &painter);
    void initAllRanges();
protected:
    QTimer *targetUpdateTimer_;
    RadarRing radar_ring_;

    std::map<unsigned int, boost::shared_ptr<target_draw_base> > all_target_draw_;

    double longitude_;
    double altitude_;
    double latitude_;

    bool is_radar_ring_follow_single_radar_;

    std::set<int> all_ranges_;
    double range_meters_;
    size_t spoke_len_;
};
